package com.estar.integaration.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.estar.integaration.Mapper.OperationHistoryMapper;
import com.estar.integaration.Service.IOperationHistoryService;
import com.estar.integaration.entity.OperationHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YJL
 * @since 2021-11-18
 */
@Service
public class OperationHistoryServiceImpl extends ServiceImpl<OperationHistoryMapper, OperationHistory> implements IOperationHistoryService {

  @Autowired
  OperationHistoryMapper operationHistoryMapper;
  @Autowired
  IOperationHistoryService iOperationHistoryService;

 //TODO    换个写法,在想

//  @Override
//  public OperationHistory insertIntoDB(String username,String time,String id,String materialNo,
//                                       String materialName,Integer thispurchase,Integer unpurchase,
//                                       Integer inventory,Integer backgoods,String purchaseDepartId) {
//      OperationHistory oh = new OperationHistory();
//      oh.setUsername(username);
//      oh.setTime(time);
//      oh.setId(id);
//      oh.setMaterialNo(materialNo);
//      oh.setMaterialName(materialName);
//      oh.setPurchaseId(purchaseDepartId);
//      oh.setThisPurchase(thispurchase);
//      oh.setUnpurchase(unpurchase);
//      oh.setInventory(inventory);
//      oh.setBackgoods(backgoods);
//      operationHistoryMapper.insert(oh);
//      return oh;
//  }

  @Override
  public void insertBatchHis(OperationHistory operationHistory) {
    List<OperationHistory> operationHistoryList = new ArrayList<>();
    if(operationHistoryList.size() > 50){
      iOperationHistoryService.saveBatch(operationHistoryList);
      operationHistoryList.clear();
    }else {
      operationHistoryList.add(operationHistory);
    }
  }
}
